import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-03
 * Time: 11:11
 */
public class DomeFunc {
    public static void reverse(int[] array) {
        int left = 0;
        int right = array.length-1;
        while(left <= right) {
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
            left++;
            right--;
        }
    }
    public static void main(String[] args) {
        //数组逆置
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        reverse(array);
        System.out.println(Arrays.toString(array));
    }

    public static boolean func2(int[] array) {
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if(array[i]%2 == 1) {
                count++;
                if(count == 3) {
                    return true;
                }
            } else {
                count = 0;
            }

        }
        return false;
    }
    public static void main5(String[] args) {
        //判断数组中是否存在连续的三个奇数
        int[] arrary = {4,5,7,11};
        boolean ret  = func2(arrary);
        System.out.println(ret);
    }

    public static int func1(int[] array) {
        int tmp = array[0];
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if (count == 0) {
                tmp = array[i];
                count++;
            } else if (tmp == array[i]) {
                count++;
            } else if (tmp != array[i]) {
                count--;
            }
        }
        return tmp;
    }
    public static void main4(String[] args) {
        //找出数组中大于 2/n 的元素
        int[] array = {6,5,5};
        int ret = func1(array);
        System.out.println(ret);
    }

    private static void bubbleSort(int[] array) {
        for (int i = 0; i < array.length-1; i++) {
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                }
            }
        }
    }
    public static void main3(String[] args) {
        //冒泡排序
        int[] array = {9,8,7,6,5,4,3,2,1,0};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
    private static int myBinarySearch(int[] array,int num) {
        int left = 0;//左下标
        int right = array.length-1;//右下标

        while(left <= right) {
            int mid = (left + right)/2;//中间下标
            if(num > array[mid]) {
                left = mid+1;
            } else if(num < array[mid]) {
                right = mid-1;
            } else {
                return mid;
            }
        }
        return -1;
    }
    public static void main2(String[] args) {
        //实现二分查找
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int ret = myBinarySearch(array,num);
            System.out.println(ret);
    }

    private static void func(int[] array) {
        int lift = 0;
        int right = array.length-1;
        while(lift < right) {
            while(lift < right && array[lift]%2 != 0) {
                lift++;
            }
            while(lift < right && array[right]%2 == 0) {
                right--;
            }
            int tmp = array[lift];
            array[lift] = array[right];
            array[right] = tmp;
        }
    }
    public static void main1(String[] args) {
        //奇数在偶数之前
        int[] array = {1,2,3,4,5,6};
        func(array);
        System.out.println(Arrays.toString(array));
    }
}
